package com.example.b_308.myapplication.view.user.register;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.RadioGroup;

import com.example.b_308.myapplication.R;
import com.example.b_308.myapplication.comment.utils.Global;
import com.example.b_308.myapplication.comment.view.page.WorkPageAdapter;
import com.example.b_308.myapplication.comment.view.page.WorkViewPager;
import com.example.b_308.myapplication.controller.UserController;
import com.example.b_308.myapplication.model.Staff;
import com.example.b_308.myapplication.view.base.BaseActivity;
import com.example.b_308.myapplication.view.base.BaseFragment;
import com.example.b_308.myapplication.view.user.login.LoginActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by B-308 on 2017/11/20.
 */
public class RegisterActivity extends BaseActivity {
    WorkViewPager workViewPagerRegister;
    RadioGroup radioGroup;
    List<BaseFragment> fragmentsRegister = new ArrayList<>();
    int current = 0;
    UserController userController;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        workViewPagerRegister = (WorkViewPager) findViewById(R.id.work_view_page_register);
        radioGroup = (RadioGroup) findViewById(R.id.rg_bottom_register);
        getTitleBar().setTitle(Global.getString(R.string.register));
        getTitleBar().getTv_setting().setVisibility(View.GONE);
        getTitleBar().getIv_setting().setVisibility(View.GONE);
        fragmentsRegister.add(new VerifyFragment().setTitle("手机验证"));
        fragmentsRegister.add(new VerifyNewPasswordFragment().setTitle("手机验证"));
        fragmentsRegister.add(new ConsummateFragment().setTitle("信息完善"));
        fragmentsRegister.add(new ConsummatePersonFragment().setTitle("信息完善"));
        fragmentsRegister.add(new RegSuccessFragment().setTitle("注册成功"));
        workViewPagerRegister.setAdapter(new WorkPageAdapter(getSupportFragmentManager(), fragmentsRegister));
        workViewPagerRegister.setCurrentItem(current);

    }

    public<T> void next(BaseFragment baseFragment,T t) {
        int index = fragmentsRegister.indexOf(baseFragment)+1;
        if(2 == index || 3 == index) {
            radioGroup.getChildAt(1).setSelected(true);
        }
        if(4 == index){
            radioGroup.getChildAt(2).setSelected(true);
        }
        if (index < 5) {
            workViewPagerRegister.setCurrentItem(index);
        } else {
            tend2(LoginActivity.class);
            finish();
        }
    }

    @Override
    public void fail(String message) {

    }
}
